package com.ruoyi.tsjData.service.impl;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.tsjData.domain.result.*;
import com.ruoyi.tsjData.mapper.*;
import com.ruoyi.tsjData.service.IDataTshjResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 提升机结果Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-22
 */
@Service
public class DataTshjResultServiceImpl implements IDataTshjResultService
{
    @Autowired(required = false)
    private DataTshjResultMapper dataTshjResultMapper;

    @Autowired(required = false)
    private DataTshjHjResultMapper dataTshjHjResultMapper;

    @Autowired(required = false)
    private DataTshjJxResultMapper dataTshjJxResultMapper;

    @Autowired(required = false)
    private DataTshjKxchResultMapper dataTshjKxchResultMapper;

    @Autowired(required = false)
    private DataTshjPbResultMapper dataTshjPbResultMapper;

    @Autowired(required = false)
    private DataTshjSdResultMapper dataTshjSdResultMapper;

    @Autowired(required = false)
    private DataTshjTyxnResultMapper dataTshjTyxnResultMapper;

    @Autowired(required = false)
    private DataTshjWshResultMapper dataTshjWshResultMapper;

    @Autowired(required = false)
    private DataTshjYyResultMapper dataTshjYyResultMapper;

    @Autowired(required = false)
    private DataTshjZhdResultMapper dataTshjZhdResultMapper;

    @Autowired(required = false)
    private DataTshjZhdlResultMapper dataTshjZhdlResultMapper;

    /**
     * 查询提升机结果
     * 
     * @param resultId 提升机结果主键
     * @return 提升机结果
     */
    @Override
    public DataTshjResult selectDataTshjResultByResultId(Long resultId)
    {   //测试结果
        DataTshjResult dataTshjResult = new DataTshjResult();
        //根据resultId获取数据
        DataTshjResultDetail dataTshjResultDetail = dataTshjResultMapper.selectDataTshjResultByResultId(resultId);
        dataTshjResult.setDataTshjResultDetail(dataTshjResultDetail);
        //获取dataTaskId
        Long dataTaskId = dataTshjResultDetail.getDataTaskId();
        //测试图数据
        String imgPath = RuoYiConfig.getChartPath();
        if(null != dataTaskId) {
            //获取环境结果数据
            List<DataTshjHjResult> dataTshjHjResults = dataTshjHjResultMapper.selectDataTshjHjResultByDataTaskId(dataTaskId, resultId);
            dataTshjResult.setDataTshjHjResult(dataTshjHjResults);
            //获取间隙结果数据
            List<DataTshjJxResult> dataTshjJxResults = dataTshjJxResultMapper.selectDataTshjJxResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjJxResults.isEmpty()) {
                dataTshjJxResults.forEach(item -> {
                    if (null != item.getWyImg()){
                            item.setWyImg(StringUtils.replace(item.getWyImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjJxResult(dataTshjJxResults);
            //空行程结果数据
            List<DataTshjKxchResult> dataTshjKxchResults = dataTshjKxchResultMapper.selectDataTshjKxchResultByDataTaskId(dataTaskId, resultId);
            dataTshjResult.setDataTshjKxchResult(dataTshjKxchResults);
            //偏摆结果数据
            List<DataTshjPbResult> dataTshjPbResults = dataTshjPbResultMapper.selectDataTshjPbResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjPbResults.isEmpty()) {
                dataTshjPbResults.forEach(item -> {
                    if(null != item.getPdImg()) {
                        item.setPdImg(StringUtils.replace(item.getPdImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjPbResult(dataTshjPbResults);
            //速度结果数据
            List<DataTshjSdResult> dataTshjSdResults = dataTshjSdResultMapper.selectDataTshjSdResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjSdResults.isEmpty()) {
                dataTshjSdResults.forEach(item -> {
                    if(null != item.getH40ssddownImg()) {
                        item.setH40ssddownImg(StringUtils.replace(item.getH40ssddownImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getH40ssdupImg()) {
                        item.setH40ssdupImg(StringUtils.replace(item.getH40ssdupImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getJsddownImg()) {
                        item.setJsddownImg(StringUtils.replace(item.getJsddownImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getJsdupImg()) {
                        item.setJsdupImg(StringUtils.replace(item.getJsdupImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getJshsddownImg()) {
                        item.setJshsddownImg(StringUtils.replace(item.getJshsddownImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getJshsdupImg()) {
                        item.setJshsdupImg(StringUtils.replace(item.getJshsdupImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getSddldownImg()) {
                        item.setSddldownImg(StringUtils.replace(item.getSddldownImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getSddlupImg()) {
                        item.setSddlupImg(StringUtils.replace(item.getSddlupImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getQ40ssddownImg()) {
                        item.setQ40ssddownImg(StringUtils.replace(item.getQ40ssddownImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getQ40ssdupImg()) {
                        item.setQ40ssdupImg(StringUtils.replace(item.getQ40ssdupImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjSdResult(dataTshjSdResults);
            //调压性能结果数据
            List<DataTshjTyxnResult> dataTshjTyxnResults = dataTshjTyxnResultMapper.selectDataTshjTyxnResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjTyxnResults.isEmpty()) {
                dataTshjTyxnResults.forEach(item -> {
                    if(null != item.getDldyyyImg()) {
                        item.setDldyyyImg(StringUtils.replace(item.getDldyyyImg(), "/chartPath", imgPath));
                    }
                    if(null != item.getSjyyImg()) {
                        item.setSjyyImg(StringUtils.replace(item.getSjyyImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjTyxnResult(dataTshjTyxnResults);
            //温升结果数据
            List<DataTshjWshResult> dataTshjWshResults = dataTshjWshResultMapper.selectDataTshjWshResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjWshResults.isEmpty()) {
                dataTshjWshResults.forEach(item -> {
                    if(null != item.getWshImg()) {
                        item.setWshImg(StringUtils.replace(item.getWshImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjWshResult(dataTshjWshResults);
            //油压结果数据
            List<DataTshjYyResult> dataTshjYyResults = dataTshjYyResultMapper.selectDataTshjYyResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjYyResults.isEmpty()) {
                dataTshjYyResults.forEach(item -> {
                    if(null != item.getYyImg()) {
                        item.setYyImg(StringUtils.replace(item.getYyImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjYyResult(dataTshjYyResults);
            //制动结果数据
            List<DataTshjZhdResult> dataTshjZhdResults = dataTshjZhdResultMapper.selectDataTshjZhdResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjZhdResults.isEmpty()) {
                dataTshjZhdResults.forEach(item -> {
                    if(null != item.getZhdsdImg()) {
                        item.setZhdsdImg(StringUtils.replace(item.getZhdsdImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjZhdResult(dataTshjZhdResults);
            //制动力结果数据
            List<DataTshjZhdlResult> dataTshjZhdlResults = dataTshjZhdlResultMapper.selectDataTshjZhdlResultByDataTaskId(dataTaskId, resultId);
            if(!dataTshjZhdlResults.isEmpty()) {
                dataTshjZhdlResults.forEach(item -> {
                    if(null != item.getZhdlImg()) {
                        item.setZhdlImg(StringUtils.replace(item.getZhdlImg(), "/chartPath", imgPath));
                    }
                });
            }
            dataTshjResult.setDataTshjZhdlResult(dataTshjZhdlResults);
        }
        return dataTshjResult;
    }

    /**
     * 查询提升机结果列表
     * 
     * @param dataTshjResult 提升机结果
     * @return 提升机结果
     */
    @Override
    public List<DataTshjResultDetail> selectDataTshjResultList(DataTshjResultDetail dataTshjResult)
    {
        return dataTshjResultMapper.selectDataTshjResultList(dataTshjResult);
    }

    /**
     * 新增提升机结果
     * 
     * @param dataTshjResult 提升机结果
     * @return 结果
     */
    @Override
    public int insertDataTshjResult(DataTshjResultDetail dataTshjResult)
    {
        dataTshjResult.setCreateTime(DateUtils.getNowDate());
        return dataTshjResultMapper.insertDataTshjResult(dataTshjResult);
    }

    /**
     * 修改提升机结果
     * 
     * @param dataTshjResult 提升机结果
     * @return 结果
     */
    @Override
    public int updateDataTshjResult(DataTshjResultDetail dataTshjResult)
    {
        dataTshjResult.setUpdateTime(DateUtils.getNowDate());
        return dataTshjResultMapper.updateDataTshjResult(dataTshjResult);
    }

    /**
     * 批量删除提升机结果
     * 
     * @param resultIds 需要删除的提升机结果主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjResultByResultIds(Long[] resultIds)
    {
        return dataTshjResultMapper.deleteDataTshjResultByResultIds(resultIds);
    }

    /**
     * 删除提升机结果信息
     * 
     * @param resultId 提升机结果主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjResultByResultId(Long resultId)
    {
        return dataTshjResultMapper.deleteDataTshjResultByResultId(resultId);
    }
}
